using GraphProcessor;
using IQIGame.Onigao.Logic;
using System;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/【过期】开关服务", typeof(LevelServiceGraph))]
    [Obsolete]
    public class LevelServiceExecutionNode_EnableService : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.EnableServiceUnit;

        public override string name => "【过期】开关服务";
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [InspectorName("是否启动")] public bool enable;
        [InspectorName("服务文件")] public BaseGraph serviceGraph;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.EnableServiceUnit, "服务", nameof(serviceGraph))]
        public int serviceGroup;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.EnableServiceUnit, "服务单元", nameof(serviceGroup))]
        public int serviceIndex;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_EnableServiceUnit()
            {
                enable = this.enable,
                service = this.serviceGroup,
                serviceUnitIndex = this.serviceIndex
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_EnableService rNode)
            {
                this.enable = rNode.enable;
                this.serviceGroup = rNode.serviceGroup;
                this.serviceIndex = rNode.serviceIndex;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_EnableServiceUnit rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}